<c:if test="true" xmlns:f="http://java.sun.com/jsf/core"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:nxu="http://nuxeo.org/nxweb/util"
  xmlns:nxp="http://nuxeo.org/nxweb/pdf"
  xmlns:nxd="http://nuxeo.org/nxweb/document"
  xmlns:c="http://java.sun.com/jstl/core"
  xmlns:rich="http://richfaces.org/rich"
  xmlns:ui="http://java.sun.com/jsf/facelets">
  <c:if test="#{nxl:isLikePlainMode(widget.mode)}">
    <h:panelGroup rendered="#{not empty field}">
      <nxu:set var="canSee"
        value="#{docSuggestionActions.getDocumentExistsAndIsVisibleWithId(field)}">
        <h:panelGroup rendered="#{canSee}">
          <nxu:set var="doc"
            value="#{docSuggestionActions.getDocumentWithId(field)}">
            <h:outputText value="#{nxd:titleOrId(doc)}" />
          </nxu:set>
        </h:panelGroup>
        <h:outputText rendered="#{not canSee}"
          value="#{messages['label.documentSuggestion.docNotFoundOrNotVisible']} (#{field})" />
      </nxu:set>
    </h:panelGroup>
  </c:if>
  <c:if test="#{widget.mode == 'pdf'}">
    <h:panelGroup rendered="#{not empty field}">
      <nxu:set var="canSee"
        value="#{docSuggestionActions.getDocumentExistsAndIsVisibleWithId(field)}">
        <nxp:html>
        <h:panelGroup rendered="#{canSee}">
          <nxu:set var="doc"
            value="#{docSuggestionActions.getDocumentWithId(field)}">
            <nxu:graphicImage value="#{nxd:iconPath(doc)}"
              rendered="#{!empty nxd:iconPath(doc)}" />
            <h:outputText value="#{nxd:titleOrId(doc)}" />
          </nxu:set>
        </h:panelGroup>
        <h:outputText
          value="#{messages['label.documentSuggestion.docNotFoundOrNotVisible']} (#{field})"
          rendered="#{not canSee}" />
        </nxp:html>
      </nxu:set>
    </h:panelGroup>
  </c:if>
  <c:if test="#{nxl:isLikeViewMode(widget.mode)}">

    <h:panelGroup rendered="#{not empty field}">
      <nxu:set var="canSee"
        value="#{docSuggestionActions.getDocumentExistsAndIsVisibleWithId(field)}">
        <h:panelGroup rendered="#{canSee}">
          <nxu:set var="doc"
            value="#{docSuggestionActions.getDocumentWithId(field)}">
            <nxu:graphicImage value="#{nxd:iconPath(doc)}"
              rendered="#{!empty nxd:iconPath(doc)}"
              style="vertical-align:middle" styleClass="smallIcon" />
            <h:outputText value=" #{nxd:titleOrId(doc)} " />
            <nxd:restDocumentLink document="#{doc}"
              newConversation="true" target="_blank"
              tab="#{widgetProperty_tab}"
              subTab="#{widgetProperty_subTab}">
              <nxu:graphicImage value="/icons/external.gif"
                style="vertical-align:middle"
                alt="#{messages['permalink.newTab']}"
                title="#{messages['permalink.newTab']}" />
            </nxd:restDocumentLink>
          </nxu:set>
        </h:panelGroup>
        <h:outputText
          value="#{messages['label.documentSuggestion.docNotFoundOrNotVisible']} (#{field})"
          rendered="#{not canSee}" />
      </nxu:set>
    </h:panelGroup>

  </c:if>
  <c:if test="#{widget.mode == 'edit'}">

    <nxu:set var="helpLabel"
      value="#{nxu:test(empty widgetProperty_helpLabel, messages['label.suggestion.help.minChars'], nxu:test(widget.translated, messages[widgetProperty_helpLabel], widgetProperty_helpLabel))}"
      cache="true">

      <ui:include src="/incl/select2_js.xhtml" />

      <a4j:region>
        <nxu:valueHolder id="#{widget.id}_select2" value="#{field_0}"
          required="#{widgetProperty_required}" var="currentValue">
          <nxu:validateDocumentConstraint />
          <h:inputHidden readonly="true" id="#{widget.id}_select2_init"
            value="#{select2Actions.resolveSingleReference(currentValue, widgetProperty_repository,widgetProperty_initOperationId, widgetProperty_idProperty,widgetProperty_documentSchemas)}" />
        </nxu:valueHolder>

        <c:if test="#{not empty widgetProperty_ajaxReRender}">
          <a4j:jsFunction name="#{widget.id}_reRender"
            render="#{widgetProperty_ajaxReRender}" />
        </c:if>

      </a4j:region>

      <c:if
        test="#{widget.mode == 'edit' and !widgetProperty_hideHelpLabel}">
        <p class="detail">
          <h:outputFormat value="#{helpLabel}">
            <f:param value="#{widgetProperty_minChars}" />
          </h:outputFormat>
        </p>
      </c:if>

      <h:inputHidden readonly="true" id="#{widget.id}_select2_params"
        value="#{select2Actions.encodeParameters(widget, widgetProperties)}" />
      <h:message for="#{widget.id}_select2" styleClass="errorMessage" />
    </nxu:set>

  </c:if>
</c:if>
